home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Dev / Orbit_SRC / screenshot.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-27  |  1.9 KB  |  80 lines

  1. /*
  2.     Amiga port by Oliver Gantert
  3.  
  4.     27.04.2000 - fixed some compiler warnings
  5. */
  6. /*
  7.  
  8. ORBIT, a freeware space combat simulator
  9. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  24.  
  25. */
  26.  
  27. #include "orbit.h"
  28.  
  29. void ScreenShot()
  30. {
  31.   char fname[32];
  32.   char *screen;
  33.   FILE *fd;
  34.   int x, y, c;
  35.  
  36.   /* Construct file name */
  37.   sprintf (fname, "orbit%03d.ppm", screen_shot_num);
  38.   screen_shot_num++;
  39.  
  40.   /* Allocate space for screen */
  41.   if (NULL == (screen = (char *) malloc (ScreenWidth*ScreenHeight*3)))
  42.   {
  43.     Cprint ("Can't allocate memory for screen shot");
  44.     return;
  45.   }
  46.  
  47.   /* Get frame buffer */
  48.   glReadPixels (0, 0, ScreenWidth, ScreenHeight, GL_RGB,
  49.   GL_UNSIGNED_BYTE, screen);
  50.  
  51.   /* Open the file */
  52.   if (NULL == (fd = fopen (fname, "wb")))
  53.   {
  54.     Cprint ("Can't open screen shot file");
  55.     free (screen);
  56.     return;
  57.   }
  58.  
  59.   /* Write the PPM file */
  60.   fprintf (fd, "P6\n%d %d\n255\n", ScreenWidth, ScreenHeight);
  61.  
  62.   for (y=0; y<ScreenHeight; y++)
  63.   {
  64.     for (x=0; x<ScreenWidth; x++)
  65.     {
  66.       c = 0xff & *screen++;
  67.       fputc (c, fd);
  68.       c = 0xff & *screen++;
  69.       fputc (c, fd);
  70.       c = 0xff & *screen++;
  71.       fputc (c, fd);
  72.     }
  73.   }
  74.  
  75.   /* Close and clean up */
  76.   fclose (fd);
  77.   free (screen);
  78.   Cprint ("Screen shot saved in %s", fname);
  79. }
  80.